<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateTaskMemberRelation extends AbstractMigration
{
    public function up()
    {
        $this->table('task_member_relation', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '任务关联标签表'])
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('task_member_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '待办成员关联id'])
            ->addColumn('link_module_code', 'string', ['null' => false, 'default' => '', 'limit' => 128, 'comment' => '关联数据module_code'])
            ->addColumn('link_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '关联数据module主键'])
            ->addColumn('user_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '待办成员id'])
            ->addColumn('task_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '任务id'])
            ->addColumn('department_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '部门id'])
            ->addColumn('created', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建时间',])
            ->addColumn('updated', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '更新时间',])
            ->addColumn('tenant_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '租户id'])
            ->addIndex(['task_member_id', 'link_module_code', 'link_id', 'department_id'], ['type' => 'unique', 'name' => 'idx_unique_task_member_department_module_link'])
            ->addIndex(['link_module_code', 'link_id'], ['type' => 'normal', 'name' => 'idx_module_link'])
            ->save();
    }

    public function down()
    {
        $this->table('task_member_relation')->drop()->save();
    }
}
